/******************************** INIT ****************************************/

$(document).ready(function(){
  /**
   *Add flash mp3 player
   */     
  var FO = {movie:"app/lib/mcz/playa.swf",id:"fookinPlay",build:"0",swliveconnect:"true",allowscriptaccess:"always", width:"1", height:"1",majorversion:"8"};
  UFO.create(FO, "playaSpace");
  
  /**
   * Enable tabs
   */     
  $('#onglets').tabs();
	
	/**
	 * Enable player slider
	 */   	
	$('.playerSlider').Slider({
      accept :'.playerCursor',
      fractions : 100,
      onSlide : function(cordx,cordy,x,y){
                    tDuration = thisMovie('fookinPlay').getDuration();
                    newPos = Math.ceil(tDuration * cordx / 100000);
                    pausition = newPos * 1000;
                    paused = false;
                    $('#btnPlayer').removeClass('btnPlay').addClass('btnPause');
                    thisMovie('fookinPlay').skipTo(newPos);
                    clearTimeout(scrobbleTimeOut);
                    scrobbleTimeOut = setTimeout("scrobble()",30000);
                }
      });
  /**
   * Enable cueList
   */     
  $('#cueList').Sortable({
    accept :'sortableItem',
    axis:'vertically',
    containment:'cueList',
    handle:'.handle',
    helperclass : 'cueItemHelper',
    opacity: 	0.5,
    onchange:function(){updateCueOrder();}
  });
  
  /**
   *Global ajax setup
   */
  $.ajaxSetup({
   url:"?c=ajax",
   timeout:20000,
   type: "POST"
   //dataType: "json"
  });     
  /**
   *Ajax monitoring
   */
  $("#ajaxStatus").ajaxStart(function(){
   $(this).show();
  });
  
  $("#ajaxStatus").ajaxStop(function(){
   $(this).hide();
  });
  
  /**
   *Update player state
   */     
  var updateLooper = setInterval("updateSlider()", 1000);
  /**
   *Keep session alive
   */     
  var keepSessionAlive = setInterval("stayAwake()",45000);
 
  /**
   *Enable pause button
   */
  document.getElementById('btnPlayer').onclick = togglePause;// jquery crashes IE here  
  
})
